package com.hzdesk.media.matvector.koreabatch.client.my_paperless.custom_view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;


/**
 * Created by Administrator on 2018/8/20.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class BrushSizeView extends View {

    private float radius;
    private Paint mpaint;
    private int width;
    private int height;
    private int widthMode;
    private int heightMode;
    private Paint tpaint;
    private boolean flag = false;

    public BrushSizeView(Context context) {
        this(context,null);
    }

    public BrushSizeView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public BrushSizeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.brush_size);
        radius = array.getDimension(R.styleable.brush_size_brush_radius,20);
        array.recycle();
        init();
    }

    private void init() {
        mpaint = new Paint();
        mpaint.setColor(0XFF000000);
        mpaint.setAntiAlias(true);

        tpaint = new Paint();
        tpaint.setAntiAlias(true);
        tpaint.setColor(0X33000000);
        tpaint.setStrokeWidth(radius);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
        if(width >= height){
            height = width;
        }
        setMeasuredDimension(width,height);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(width/2,width/2,radius,mpaint);
        if(flag){
            canvas.drawArc(new RectF((width/2)-(3*radius)/2,(width/2)-(3*radius)/2,(width/2)+(3*radius)/2,(width/2)+(3*radius)/2),0,360,false,tpaint);
        }
    }

    /**
     * @desc 选中
     * */
    public void showSelect(){
        flag = true;
        invalidate();
    }
    /**
     * @desc 未选中
     * */
    public void hidenSelect(){
        flag = false;
        invalidate();
    }



}
